feat: implement addItemToReturnArray method#69
Conversation
|
It inherits from this commit: #64 |
Coverage Report for CI Build 27291937801Coverage increased (+0.2%) to 98.853%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b3b724c1f4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
b3b724c to
2d7ffe6
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d7ffe63e6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3fadeec638
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| protected function parsePHPCode(string $code): array | ||
| { | ||
| try { | ||
| $stmts = new ParserFactory()->createForHostVersion()->parse("<?php\n{$code};"); |
There was a problem hiding this comment.
Reject statements before embedding array values
When addItemToReturnArray() is called with syntactically valid PHP that is not a single expression, such as return 1 or $a = 1; $b = 2, this parser accepts it here and PreformattedExpression later prints the raw text inside an array item. That produces invalid generated PHP like return [return 1,]; instead of throwing InvalidPHPCodeException, so callers can corrupt the target file with an input that passed validation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Validate PHP syntax only. Semantic correctness of the value is the caller's responsibility, like elsewhere in this library.
3fadeec to
cf924f2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cf924f2562
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
💡 Codex ReviewWhen the target method contains a closure or anonymous function before its own returned array, ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca7af3fd92
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| protected function validatePHPCode(string $code): void | ||
| { | ||
| try { | ||
| new ParserFactory()->createForHostVersion()->parse("<?php\n{$code}?>"); |
There was a problem hiding this comment.
Reject statements before embedding expressions
When $value or $key is a syntactically valid PHP statement but not an expression (for example return 1; or if ($x) {}), this validation succeeds because it parses the snippet as a whole PHP file. The same raw text is then printed inside an array item expression by AddItemToReturnArray, producing an invalid PHP file instead of throwing InvalidPHPCodeException; validate these snippets specifically as expressions before accepting them.
Useful? React with 👍 / 👎.
refs: #71